/////////////////////////////////////////////////////////////////////////////
// Name:        dgt_SyntezTab.cpp
// Purpose:     
// Author:      Aleksey Plotnikov & Alla Nabatova
// Modified by: 
// Created:     05/11/2008 19:08:36
// RCS-ID:      
// Copyright:   Diamant Software
// Licence:     
/////////////////////////////////////////////////////////////////////////////

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "dgt_SyntezTab.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "dgt_SyntezTab.h"
#include "dgt_PluginManager.h"
#include "dgt_StudioApp.h"
#include "dgt_SyntezCAPlugin.h"
#include "dgt_SyntezOAPlugin.h"

////@begin XPM images
////@end XPM images


/*!
 * dgt_SyntezTab type definition
 */

IMPLEMENT_DYNAMIC_CLASS( dgt_SyntezTab, wxPanel )


/*!
 * dgt_SyntezTab event table definition
 */

BEGIN_EVENT_TABLE( dgt_SyntezTab, wxPanel )

////@begin dgt_SyntezTab event table entries
    EVT_GRID_CELL_LEFT_CLICK( dgt_SyntezTab::OnCellLeftClick )

////@end dgt_SyntezTab event table entries

END_EVENT_TABLE()


/*!
 * dgt_SyntezTab constructors
 */

dgt_SyntezTab::dgt_SyntezTab()
{
    Init();
}

dgt_SyntezTab::dgt_SyntezTab(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{
    Init();
    Create(parent, id, pos, size, style);
}


/*!
 * dgt_SyntezTab creator
 */

bool dgt_SyntezTab::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{
////@begin dgt_SyntezTab creation
    wxPanel::Create(parent, id, pos, size, style);
    CreateControls();
    if (GetSizer())
        GetSizer()->Fit(this);
////@end dgt_SyntezTab creation
    return true;
}


/*!
 * dgt_SyntezTab destructor
 */

dgt_SyntezTab::~dgt_SyntezTab()
{
////@begin dgt_SyntezTab destruction
////@end dgt_SyntezTab destruction
}


/*!
 * Member initialisation
 */

void dgt_SyntezTab::Init()
{
////@begin dgt_SyntezTab member initialisation
    m_SyntezGrid = NULL;
    m_AboutPl = NULL;
////@end dgt_SyntezTab member initialisation
}


/*!
 * Control creation for dgt_SyntezTab
 */

void dgt_SyntezTab::CreateControls()
{    
////@begin dgt_SyntezTab content construction
    dgt_SyntezTab* itemPanel1 = this;

    this->SetName(_T("Syntez"));
    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemPanel1->SetSizer(itemBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);

    m_SyntezGrid = new dgt_PluginGrid( itemPanel1, ID_GRID3, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
    m_SyntezGrid->SetDefaultColSize(50);
    m_SyntezGrid->SetDefaultRowSize(25);
    m_SyntezGrid->SetColLabelSize(25);
    m_SyntezGrid->SetRowLabelSize(50);
    m_SyntezGrid->CreateGrid(1, 4, wxGrid::wxGridSelectCells);
    itemBoxSizer3->Add(m_SyntezGrid, 1, wxGROW|wxALL, 5);

    m_AboutPl = new wxStaticText( itemPanel1, wxID_STATIC, _("Select a plugin"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
    m_AboutPl->SetFont(wxFont(10, wxSWISS, wxNORMAL, wxNORMAL, false, wxT("Tahoma")));
    itemBoxSizer2->Add(m_AboutPl, 0, wxALIGN_LEFT|wxALL, 5);

////@end dgt_SyntezTab content construction

	m_SyntezGrid->SetGridMode();
	m_SyntezGrid->SetCheckBox(1);

	SetPluginInfo();
}




/*!
 * Should we show tooltips?
 */

bool dgt_SyntezTab::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap dgt_SyntezTab::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin dgt_SyntezTab bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end dgt_SyntezTab bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon dgt_SyntezTab::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin dgt_SyntezTab icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end dgt_SyntezTab icon retrieval
}

/*!
 * wxEVT_GRID_CELL_LEFT_CLICK event handler for ID_GRID3
 */

void dgt_SyntezTab::OnCellLeftClick( wxGridEvent& event )
{
	if (m_SyntezGrid->GetCellValue(0,0)!=_T(""))
	{
		wxString string;
		int n=event.GetRow();
		string = array_string.Item(n);
		m_AboutPl->SetLabel(string);
	}

////@begin wxEVT_GRID_CELL_LEFT_CLICK event handler for ID_GRID3 in dgt_SyntezTab.
    // Before editing this code, remove the block markers.
    event.Skip();
////@end wxEVT_GRID_CELL_LEFT_CLICK event handler for ID_GRID3 in dgt_SyntezTab. 
}

/*************************************************************/
//Set info about plugin into the grid
void dgt_SyntezTab::SetPluginInfo()
{
	dgt_StudioApp *tApp =(dgt_StudioApp*) wxApp::GetInstance();
	dgt_PluginManager *pManager = tApp->get_Manager();

	dgt_PluginInfo info;
	int row_numb = 0;
	short tPlugin_type = (short) PLUGIN_SYNTEZ_OA;
	unsigned qRows = 1;

	for( short j = tPlugin_type; j<= (short) PLUGIN_SYNTEZ_CA; j++ )
	{
		int number = pManager->get_PluginCount( (PLUGIN_TYPE) j );
		if( !number )
			continue;

		int RowToAdd;
		if( qRows == 1)
			RowToAdd = number - 1;
		else
			RowToAdd = number;

		qRows += number;

		if( RowToAdd )
			m_SyntezGrid->AppendRows( RowToAdd );

		for( int i = number; i > 0; i-- )
		{ 
			dgt_Plugin_Ptr plugin = pManager->get_Plugin( (PLUGIN_TYPE) j , i - 1 );

			if( pManager->IsLoaded( i - 1 ))
			{
				m_SyntezGrid->SetCellValue( _T("1"), row_numb, 1 );
			}

			plugin->GetPluginInfo( info );
			wxString sDllName = pManager->get_PluginDllName((PLUGIN_TYPE) j, i - 1 );
			m_SyntezGrid->SetCellValue(sDllName,row_numb,0);

			wxString t_str = info.m_PluginName;
			m_SyntezGrid->SetCellValue(t_str,row_numb,2);

			t_str = info.m_Version;
			m_SyntezGrid->SetCellValue(t_str,row_numb,3);

			t_str = info.m_Description;
			array_string.Add(info.m_Description);

			m_SyntezGrid->SetReadOnly(row_numb,0);
			m_SyntezGrid->SetReadOnly(row_numb,2);
			m_SyntezGrid->SetReadOnly(row_numb,3);
			row_numb++;
		}
	}
}

